using Game.Main.Model;
using UnityEngine;

namespace Game.Component
{
	public class PaintBrushItem : BaseItem
	{
		private PaintBoardItem targetBoard;

		public override void Init(ItemArchiveData data)
		{
			base.Init(data);
		}

		public override void TouchDown(TouchEventData touchEventData)
		{
			base.TouchDown(touchEventData);
			CheckPaintBoard(touchEventData);
		}

		public override void TouchMove(TouchEventData touchEventData)
		{
			base.TouchMove(touchEventData);
			CheckPaintBoard(touchEventData);
		}

		public override void TouchUp(TouchEventData touchEventData)
		{
			base.TouchUp(touchEventData);
			if (targetBoard != null)
			{
				targetBoard.PaintUp(touchEventData, base.itemData.color);
				targetBoard = null;
			}
		}

		private void CheckPaintBoard(TouchEventData touchEventData)
		{
			if (targetBoard == null)
			{
				RaycastHit2D raycastHit2D = Physics2D.Raycast(base.transform.position, Vector2.zero, 0f, 512);
				if (raycastHit2D.collider != null && raycastHit2D.collider.transform != null && raycastHit2D.collider.transform.parent != null)
				{
					BaseItem component = raycastHit2D.collider.transform.parent.GetComponent<BaseItem>();
					if (component != null && component.itemData.scriptType == 2)
					{
						targetBoard = (PaintBoardItem)component;
						targetBoard.PaintDown(touchEventData, base.itemData.color);
					}
				}
			}
			else
			{
				targetBoard.PaintMove(touchEventData, base.itemData.color);
			}
		}
	}
}
